<script lang="ts" setup>
import { get, post, message, loadFile } from '@/utils'
import Editor from '@/components/Editor/index.vue'
import { FormInstance } from '@arco-design/web-vue'
import { RefundOrderStatus } from '@/enum/order'
import useOptions from '@/hooks/useOptions'
const props = defineProps<{
  show: boolean
  id: number | string
  info: any
}>()
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const formRef = ref() as Ref<FormInstance>
const detail = reactive({
  sellerMsg: '',
  id: props.id,
  status: '',
  sellerAddressId: '',
})
const submit = done => {
  formRef.value.validate(err => {
    if (!err) {
      const query = Object.assign({}, detail)
      let url = ''

      if (props.info.refundType == 1) {
        if (props.info.refundStatus == RefundOrderStatus.待审核) {
          url = '/server-shop/admin/order/refund/shipping/agree'
        }
      } else {
        if (props.info.refundStatus == RefundOrderStatus.用户寄回) {
          url = '/server-shop/admin/order/refund/shipping/agree'
        } else {
          url = '/server-shop/admin/order/refund/apply/agree'
        }
      }
      if (detail.status == 'false') url = '/server-shop/admin/order/refund/reject'
      console.log(props.info)
      post(
        { url, data: query },
        ({ code, msg }) => {
          message({
            type: code == 200 ? 'success' : 'error',
            content: msg,
          })
          emit('update:show', false)
          emit('confirm')
          done(true)
        },
        () => done(false)
      )
    } else done(false)
  })
}
const addressList = ref<any[]>([])
const getAddressList = () => {
  get({ url: '/server-shop/admin/seller/address/list', data: { sellerId: props.info.sellerId } }, ({ data }) => {
    data.forEach(item => {
      addressList.value.push({
        label: `${item.province}-${item.city}-${item.district} ${item.address}`,
        value: item.id,
      })
    })
  })
}
getAddressList()
</script>
<template>
  <CModal v-model:visible="props.show" @before-ok="submit" :mask-closable="false" title="审核" @cancel="emit('update:show', false)">
    <div class="content">
      <a-form :model="detail" ref="formRef" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 16 }">
        <a-form-item label="审核结果" field="status" :rules="[{ required: true, message: '请选择审核结果' }]" :validate-trigger="['change', 'blur']">
          <a-radio-group
            v-model="detail.status"
            :options="[
              { label: '审核通过', value: 'true' },
              { label: '审核不通过', value: 'false' },
            ]"
            type="button"
          />
        </a-form-item>
        <a-form-item label="售后地址" field="sellerAddressId" v-if="props.info.refundType == 2 && detail.status == 'true' && $props.info.refundStatus != RefundOrderStatus.用户寄回" :rules="[{ required: true, message: '请选择审核结果' }]" :validate-trigger="['change', 'blur']">
          <a-select :options="addressList" v-model="detail.sellerAddressId" placeholder="请选择" />
        </a-form-item>
        <a-form-item v-if="detail.status == 'false'" label="拒绝原因" field="sellerMsg" :rules="[{ required: true, message: '请输入拒绝原因' }]" :validate-trigger="['change', 'blur']">
          <a-textarea v-model="detail.sellerMsg" placeholder="请输入拒绝原因" />
        </a-form-item>
      </a-form>
    </div>
  </CModal>
</template>
<style lang="less" scoped></style>
